#include "cCopyData.h"

int cCopyData::Copy(int Width,  RECT data, u16 *pnt){///data size is basically size of u8 or u16 ie 1 or 2

	int x=0;  // DON'T NEED THIS
	int y=0;
//First kill buffer

///Set datahold rect
	
  	DataHold.left=0;
    DataHold.top = 0;
	DataHold.bottom =data.bottom-data.top;
	DataHold.right = data.right - data.left;
	CopyWidth=Width;
//resize the copy buffer
	//buffersize=(DataHold.right + (DataHold.bottom*Width))*datasize;
	//buffer = new u8[buffersize];
	buffer.resize((DataHold.right * DataHold.bottom)*2);
	std::fill( buffer.begin(), buffer.end(), 0 );

    u16* dst = &buffer[0];                   // pointer to start of dest
    u16* src = pnt;
		for(y = 0; y < DataHold.bottom; y++){
			for(x=0;x< DataHold.right;x++){
	
	    dst[x+(y*DataHold.right)]=src[(data.left+x)+((data.top+y)*Width)];
		}
	}
return 0;

}
int cCopyData::Paste(u16 *pnt){
	int x=0;  // DON'T NEED THIS
    int y=0;
	if(buffer.size()==0){
		MessageBox(0,"Please copy a tile first.","None",MB_OK);
		return 0;
	}
    u16* src =&buffer[0];                   // pointer to start of dest
    u16* dst =pnt;  // pointer to start of source
	for(y=0;y<DataHold.bottom;y++){ 
		for(x=0;x<DataHold.right;x++){

           dst[x + (y) * (CopyWidth)]=src[x+(y*DataHold.right)];
			//ThisLevelData->TileBuf2D[x + (y) * (CopyWidth)]=src[x+(y*DataHold.right)];
		}
	}


return 0;

}



cCopyData::cCopyData(){
}

cCopyData::~cCopyData(){

}

void cCopyData::Dump(){/*
FILE* fp = fopen("C:\\Users\\Matt\\Desktop\\Super Metroid (JU) [!]\\Test\\copydump.bin","w+");
int thissize=buffer.size();
if(fp){
fseek(fp,0,SEEK_SET);
fwrite(&buffer[0],thissize,1,fp);

fclose(fp);
}

*/

}
